/**
 * 
 */
//判断是否为空
function isEmpty(obj){
    if(typeof obj == "undefined" || obj == null || obj == "" || obj=="null"){
        return true;
    }else{
        return false;
    }
}   
//删除新闻
function deleNewById(nid){
	var id=nid;
	var flag=confirm("确认删除该新闻吗？");
    if(flag){
    	$.ajax({
			url:"/NewsManager_SSM/newsServlet/deleNewById/"+id,
			type:"post",
			success:function(result,testStatus)
			{
				if(result == "1"){
					alert("删除成功！");
					window.location.reload();
				}else{
					alert("删除失败！");
				}
			},
			error:function(xhr,errrorMessage,e){
				alert("系统异常！");
			}
		});
    }
}
//修改新闻
function updateNew(nid){
	var id=nid;
	location.href="/NewsManager_SSM/newsServlet/seleOneNew/"+id;
}
//注册用户的验证
function sub() {
	//id是用户名
	var $uid=$("#uid").val();
	var $uname=$("#mail").val();
	var $upwd=$("#upwd").val();
	var $upwd2=$("#upwd2").val();
	//邮箱正则
	//var emailReg = /^\w{3,}(\.\w+)*@[A-z0-9]+(\.[A-z]{2,5}){1,2}$/;
	//注册校验  空格清除
	if(!$.trim($uid).length>0){	
		alert("用户名不能为空");
		return false;
	}else if(!$.trim($uname).length>0){
		alert("邮箱不能为空");	
		return false;
	}else if(!$upwd==$upwd2){
		alert("两次密码应该一样");
		return false;
	}
	//else if(!emailReg.test("1712229564@qq.com")){
	//	alert("邮箱格式不对哦");
	//}
	else{
		$.ajax({
				url:"/NewsManager_SSM/managerServlet/addManager",
				type:"post",
				data:"id="+$uid+"&uname="+$uname+"&upwd="+$upwd, 
				success:function(result,testStatus)
				{
					if(result == "1"){
						alert("恭喜注册成功");	
						//跳转
						
					}else{
						alert("抱歉您注册失败");
					}
				},
				error:function(xhr,errrorMessage,e){
					alert("系统异常！");
				}
			});
	}
}
//增加新闻的验证
function addNew() {	
	var $title=$("#title").val();
	var $context=$("#context").val();
	var $user=$("#user").val();
	var $sort=$("#sort").val();
	//验证
	if(isEmpty($.trim($user))){
		confirm("抱歉，请先登录");
	}else if(isEmpty($.trim($title))){
		confirm("标题不能为空");
	}else if(isEmpty($.trim($context))){
		confirm("内容不能为空");
	}else if(isEmpty($.trim($sort))){
		confirm("请勾选类别");
	}else{
		$.ajax({
			url:"/NewsManager_SSM/newsServlet/addNew",
			type:"post",
			data:"title="+$title+"&context="+$context+"&user="+$user+"&sort="+$sort, 
			success:function(result,testStatus)
			{
				if(result == "1"){
					alert("发表成功！");					
				}else{
					alert("发表失败！");
				}
			},
			error:function(xhr,errrorMessage,e){
				alert("系统异常！");
			}
		});
	}
		
	}
	